from fastapi import APIRouter, UploadFile, File, Form
from fastapi.responses import Response
from utils.image_utils import load_image, save_image
from processing.resize import resize_image
from processing.filter import apply_filter
from processing.enhance import enhance_image

router = APIRouter()

@router.post("/resize")
async def resize(file: UploadFile = File(...), width: int = Form(...), height: int = Form(...)):
    img = load_image(await file.read())
    result = resize_image(img, width, height)
    return Response(content=save_image(result), media_type="image/png")

@router.post("/filter")
async def filter(file: UploadFile = File(...), filter_type: str = Form(...)):
    img = load_image(await file.read())
    result = apply_filter(img, filter_type)
    return Response(content=save_image(result), media_type="image/png")

@router.post("/enhance")
async def enhance(file: UploadFile = File(...), factor: float = Form(...)):
    img = load_image(await file.read())
    result = enhance_image(img, factor)
    return Response(content=save_image(result), media_type="image/png")